<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../layui/layui.all.js"  media="all">
</head>
<body>
<!--表单-->
<!--添加缺陷类型-->
<form id="defect_table" class="layui-form" method="" action="" style="margin-top: 30px;margin-left: 30px">
    <input type="hidden" name="id">
    <!--第一个-->
    <div style="float: left;">
        <!--缺陷类型-->
        <div class="layui-form-item" >
            <label class="layui-form-label" style="text-align: left">任务编号:</label>
            <div class="layui-input-inline">
                <input type="text" id="sovle_task" name="sovle_task"   lay-verify="required|sovle_task" autocomplete="off" placeholder="请输入任务编号" class="layui-input">

            </div>
            <label class="layui-form-label" style="text-align: left">任务名称：</label>
            <div class="layui-input-inline">
                <input type="text" id="solve_name" name="solve_name"   lay-verify="required|solve_name" autocomplete="off" placeholder="请输入任务名称" class="layui-input">
            </div>
            <label class="layui-form-label" style="text-align: left">工作单据:</label>
            <div class="layui-input-inline">
                <select name="work_id">
                    <option value ="0">请选择</option>
                    <option value ="1">任务单</option>
                    <option value="2">第一种单据</option>
                    <option value="3">第二种单据</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label" style="text-align: left">下发人:&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" disabled id="user_name" name="user_name"   lay-verify="required|user_name" autocomplete="off" placeholder="请输入任务编号" class="layui-input">
            </div>
            <input type="hidden" disabled id="user_id" name="user_id">

            <label class="layui-form-label" style="text-align: left">下发日期:</label>
            <div class="layui-input-inline">
                <input type="date" id="lssue_time" name="lssue_time"   lay-verify="required|lssue_time" autocomplete="off" placeholder="请输入下发时间" class="layui-input">
            </div>
            <label class="layui-form-label" style="text-align: left">完好率:</label>
            <div class="layui-input-inline">
                <input type="text" id="intact" name="intact"  placeholder="%" lay-verify="required|intact" autocomplete="off" placeholder="请输入缺陷的完好率" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label"style="text-align: left">缺陷级别:</label>
            <div class="layui-input-inline">
                <select name="defect_id">
                    <option value ="0">请选择</option>
                    <option value ="1">一般</option>
                    <option value="2">紧急</option>
                    <option value="3">严重</option>
                </select>
                <div>
                </div>
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label" style="margin-right: 200px;text-align: left">任务描述：
                <textarea name="sovle_dec" id="sovle_dec" cols="30" rows="2" style="margin-left:0px"></textarea>&nbsp;&nbsp;
            </label>
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
            <label class="layui-form-label" style="margin-right: 200px;text-align: left">备注：
                <textarea name="sovle_remarks" id="remarks" cols="30" rows="2" style="margin-left:0px"></textarea>&nbsp;&nbsp;
            </label>
            &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
            <label class="layui-form-label"  style="width: 160px;text-align: left">消缺员：
                <select name="sovle_account" id="sovle_account" lay-filter="xmFilter" style="width: 400px">
                    <option value=""></option>
                    <option value=""></option>
                    <option value=""></option>
                    <option value=""></option>
                    <option value=""></option>
                </select>
            </label>
            <div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <span style="margin-left: -100px" >缺陷任务列表</span>
        </div>
        <div class="layui-card-body">
            <!--数据表格-->
            <table class="layui-hide" id="defect" lay-data="{id: 'defect'}"lay-filter="defect_table"></table>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="formDemo1" lay-filter="formDemo1" style="margin-left: 350px" >提交</button>
        </div>
    </div>
    <!--表格中操作：编辑、删除-->
    <script type="text/html" id="operation">
        <a class="layui-btn layui-btn-xs" lay-event="delete">移除</a>
    </script>
</form>
<script src="../layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','laydate','table','layer'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , laydate = layui.laydate
            , layedit = layui.layedit
            , form = layui.form
            ,layer=layui.layer
            ,table=layui.table;
        var element = layui.element;
        var user = JSON.parse(sessionStorage.getItem("users"));
        $("#user_name").val(user[0].user_name);
        $("#user_id").val(user[0].user_account);
        table.render({
            elem: '#defect'
            // ,id:'defect'
            , url: '/defectGrade'
            , toolbar: '#toolbarDemo'
            , title: '制定消缺任务'
            , totalRow: false
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'defect_details_id', title: '缺陷详情编号',sort:true}
                , {field: 'line_id', title: '线路编号'}
                , {field: 'tower_id', title: '杆塔编号'}
                , {field: 'intact', title: '完好率'}
                , {field: 'defect_grade_name', title: '缺陷级别'}
                , {field: 'defect_name', title: '缺陷类型',}
                , {field: 'defect_des', title: '缺陷描述'}
                , {field: 'user_name', title: '发现人员'}
                , {field: 'find_time', title: '发现时间', templet: "<div>{{layui.util.toDateString(d.find_time, 'yyyy-MM-dd')}}</div>"}
                , {fixed: 'right', title: '操作', toolbar: '#operation', width: 80, align: 'center',},
            ]]
            , page: {
                limits: [5, 10, 15, 20]
            },
            even: true
            , done: function (res, curr, count) {
                console.log(res);
            }
        });
        $.ajax({
            url:"/queryOption",
            data:{},
            dataType:"json",
            type: 'post',
            success: function (data) {

//                   console.log(data);//下面会提到这个data是什么值
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    $('#sovle_account').append(new Option(value.user_account,value.user_account));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });
        form.on('submit(formDemo1)', function (data) {
            var checkStatus = table.checkStatus('defect');
            var data1 = checkStatus.data;
            console.log(data1.field);
            var value={
                sovle_task:data.field.sovle_task,
                solve_name:data.field.solve_name,
                work_id:data.field.work_id,
                user_id:data.field.user_id,
                lssue_time:data.field.lssue_time,
                defect_id:data.field.defect_id,
                sovle_dec:data.field.sovle_dec,
                intact:data.field.intact,
                sovle_remarks:data.field.sovle_remarks,
                sovle_account:data.field.sovle_account,
                key2:data1,
            };
            $.ajax({
                url: "/addSolve",
                type: "POST",
                dataType: "json",
                data: JSON.stringify(value),
                success: function (res) {
                    if (res.code == 200) {
                        parent.layer.close(parent.layer.index);
                        console.log(res.code);
                    } else if (res.code == 500) {
                        layer.msg(res.msg, {icon: 5});
                    } else if (res.code == 405) {
                        layer.msg(res.msg, {icon: 5});
                    }
                }, end: function () {
                    //执行重载
                    table.reload('defect_table', {
                        where: {
                            key: {
                                time: new Date()
                            }
                        }
                    }, 'data');
                    layer.close(index);
                }
            });
        });
        form.verify({
            intact: function(value){
                var reg=/^[1-9]\d?$/;
                if(!reg.test(value)){
                    return '完好率为0-100';
                }
            },
        });
    });
</script>

</body>
</html>